package com.ruoyi.web.controller.material.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.controller.material.entity.request.SupplierAddRequest;
import com.ruoyi.web.controller.material.entity.request.SupplierPageRequest;
import com.ruoyi.web.controller.material.entity.ylProductCategory;
import com.ruoyi.web.controller.material.entity.ylSupplier;
import com.ruoyi.web.controller.material.service.SupplierService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

/**
 * 供应商信息Controller
 *
 * @author jzx
 * @date 2025-10-21
 */

@RestController
@RequestMapping("/admin/Supplier")
public class SupplierController extends BaseController {

    @Resource
    private SupplierService supplierService;

    @PermitAll
    @Anonymous
    @GetMapping("/listAll")  // /admin/Supplier/page
    @Operation(summary = "物品分类列表查询")
    public TableDataInfo getListAll(SupplierPageRequest supplierPageRequest) {
        List<ylSupplier> list = supplierService.getPage(supplierPageRequest);
        return getDataTable(list);
    }

    @PermitAll
    @Anonymous
    @GetMapping("/page")  // /admin/Supplier/page
    @Operation(summary = "列表查询")
    public TableDataInfo getPage(SupplierPageRequest supplierPageRequest) {
        startPage();
        List<ylSupplier> list = supplierService.getPage(supplierPageRequest);
        return getDataTable(list);
    }

    @PermitAll
    @Anonymous
    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public AjaxResult delete(@PathVariable Long[] id) {
        supplierService.delete(id);
        return success();
    }

    @PermitAll
    @Anonymous
    @PostMapping("/add")
    @Operation(summary = "新增供应商")
    public AjaxResult add(@Validated @RequestBody SupplierAddRequest supplierAddRequest) {
        supplierService.add(supplierAddRequest);
        return success();
    }


    @GetMapping(value = "/{id}")
    @Operation(summary = "查询明细")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(supplierService.selectById(id));
    }

    @PermitAll
    @Anonymous
    @PostMapping("/update")
    @Operation(summary = "修改供应商")
    public AjaxResult update(@Validated @RequestBody SupplierAddRequest supplierAddRequest) {
        supplierService.update(supplierAddRequest);
        return success();
    }
}
